<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            box-sizing: border-box;
        }

        input {
            outline: none;
            border: 1px solid #000;
        }

        .clickBox {
            text-align: center;
            cursor: pointer;
        }

        .login-box {
            display: none;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            z-index: 999;
            width: 400px;
            background-color: #fff;
            padding-bottom: 10px;
            text-align: center;
            box-shadow: 0px 0px 20px #ddd;
        }

        .close {
            position: absolute;
            top: -20px;
            right: -20px;
            width: 40px;
            height: 40px;
            border-radius: 20px;
            text-align: center;
            line-height: 40px;
            background-color: #fff;
            font-size: 13px;
            cursor: pointer;
        }

        .title {
            font-size: 20px;
            margin: 10px 0;
            cursor: move;
        }

        label[for="userName"],
        label[for="password"] {
            display: inline-block;
            width: 70px;
            text-align: right;
        }

        .sub,
        .name,
        .psd {
            margin-top: 20px;
        }

        .mask {
            display: none;
            position: fixed;
            background-color: #000;
            opacity: .3;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
        }
    </style>
    <script>
        window.addEventListener('DOMContentLoaded', function () {
            var clickBox = document.querySelector('.clickBox');
            var loginBox = document.querySelector('.login-box');
            var mask = document.querySelector('.mask');
            var close = document.querySelector('.close');
            var title = document.querySelector('.title');
            clickBox.addEventListener('click', function () {
                loginBox.style.display = 'block';
                mask.style.display = 'block';
            });
            close.addEventListener('click', function () {
                loginBox.style.display = 'none';
                mask.style.display = 'none';
            });
            title.addEventListener('mousedown', function (e) {
                console.log(e)
                var x = e.pageX - loginBox.offsetLeft;
                var y = e.pageY - loginBox.offsetTop;
                document.addEventListener('mousemove', move);
                function move(e) {
                    loginBox.style.left = e.pageX - x + 'px';
                    loginBox.style.top = e.pageY - y + 'px';
                }
                document.addEventListener('mouseup', function () {
                    document.removeEventListener('mousemove', move);
                });
            });
        });
    </script>
</head>

<body>
    <div class="clickBox">点击，弹出登录框</div>
    <div class="login-box">
        <div class="close">关闭</div>
        <div class="title">登录会员</div>
        <form action="#">
            <div class="name">
                <label for="userName">用户名:</label>
                <input type="text" name="userName">
            </div>
            <div class="psd">
                <label for="password">登陆密码:</label>
                <input type="password" name="password">
            </div>
            <div class="sub">
                <button type="submit">
                    登录会员
                </button>
            </div>
        </form>
    </div>
    <div class="mask"></div>
</body>

</html>